package com.fenghen.demo01.service;

import com.fenghen.demo01.aspect.LogExecutionTimeAspect;
import com.fenghen.demo01.config.MyAppconfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
public class MyAppconfigService {
    private static final Logger logger = LoggerFactory.getLogger(MyAppconfigService.class);

    @Autowired
    private MyAppconfig myAppconfig;
    public void performAction() {
        if (myAppconfig.isFeatureEnabled()) {
            logger.error("Feature is enabled.");
            logger.error("Max Retries: " + myAppconfig.getMaxRetries());
            logger.error("Timeout: " + myAppconfig.getTimeout() + "ms");
            System.out.println("Feature is enabled.");
        } else {
            logger.error("Feature is disabled.");
            System.out.println("Feature is disabled.");
        }
    }

    @Value("${myapp.feature-enabled}")
    private boolean featureEnabled;

    @Value("${myapp.max-retries}")
    private int maxRetries;

    @Value("${myapp.timeout}")
    private int timeout;

    public void testvalue() {
        if (featureEnabled) {
            System.out.println("Feature is enabled.");
            System.out.println("Max Retries: " + maxRetries);
            System.out.println("Timeout: " + timeout + "ms");
        } else {
            System.out.println("Feature is disabled.");
        }
    }
}
